﻿using MediatR;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto;
using RBAC.Common.Dto.ProSorce;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.culture
{
    public class SourceManageHander : IRequestHandler<SourceManageCommond, Rulst>
    {

        private readonly IbaseRpository<TranceSelect> _Tranceselcet;

        public SourceManageHander(IbaseRpository<TranceSelect> tranceselcet)
        {
            _Tranceselcet = tranceselcet;
        }

        public async Task<Rulst> Handle(SourceManageCommond request, CancellationToken cancellationToken)
        {

            var list = new Rulst() {Code=(int)Reult.success };


            var result = _Tranceselcet.Query().Where(x => x.pid == 0).Select(x => new SourceSelect()
            {
                Label = x.TranceName,
                Value = x.Tranceid,
                NEWChildren = _Tranceselcet.Query().Where(s => s.pid == x.Tranceid).Select(k => new SourceSelect()
                {
                    Label = k.TranceName,
                    Value = k.Tranceid,
                    NEWChildren = _Tranceselcet.Query().Where(t => t.pid == k.Tranceid).Select(t => new SourceSelect()
                    {
                        Label = t.TranceName,
                        Value =t.Tranceid,
                        NEWChildren = new List<SourceSelect>()

                    }).ToList()

                }).ToList()

            }).ToList();


            list.data = result;


            return list;

        }



    }
}
